package com.hibase.core.mybatis.registrar;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.hibase.core.mybatis.constant.HibaseSqlMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

import java.util.Map;

/**
 * @author chenfeng
 * @version 1.0
 * @date 2022/1/6 17:04
 * @des https://gitee.com/cheershi
 */
public class LogicDeleteByMap extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        HibaseSqlMethod sqlMethod = HibaseSqlMethod.LOGIC_DELETE_BY_MAP;
        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), this.sqlLogicSet(tableInfo), this.sqlWhereByMap(tableInfo));
        SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, Map.class);
        return this.addUpdateMappedStatement(mapperClass, Map.class, sqlMethod.getMethod(), sqlSource);
    }
}
